package guiCode;

import java.sql.SQLException;

import com.sun.rowset.CachedRowSetImpl;

import flexibility.userData;
import basic.ClientConsole;

public class parentViewCode {
	
	private Integer  ParentIDId;
	private ClientConsole parentConn;
	private userData userInfo = new userData();
	private CachedRowSetImpl crs;
	private ClientConsole startConnection;
	public String parentBlockedToArr[];   //contain all Student ID which the parent block to
	
	
	
	public void setID(Integer whoAmI){
		this.ParentIDId=whoAmI;
	}
	public void setConnection(ClientConsole conn){
		startConnection= conn;
	}
	public ClientConsole getConnection() {
		return  this.parentConn;
	}
	public String getParentName() {
		
		userInfo.deleteAll();// reset user info
		userInfo.addData(68);
		userInfo.addData(1);
		userInfo.addData(ParentIDId);
		startConnection.acceptMsg(userInfo);
		try {
		crs=startConnection.getResults();
		crs.next();
		return 	crs.getString("parentLastName").concat(", ").concat(crs.getString("parentFirstName"));
		} 
		catch (SQLException e) {
			e.printStackTrace();
			return null;
			
		}
		
	}
public String[] getParentStudents() {
		String s[] = new String[1000];
		userInfo.deleteAll();// reset user info
		userInfo.addData(69);
		userInfo.addData(1);
		userInfo.addData(ParentIDId);
		startConnection.acceptMsg(userInfo);
		try {
		crs=startConnection.getResults();
		
		for(int i=1;i<=crs.size();i++){
			crs.next();
			/*if(crs.getString("isBlocked").equals("1"))//parentvsstudent.isBlocked   students.studentLastName  students.studentFirstName
				parentBlockedToArr[i]=(String) crs.getString("studentID");*/
			
			s[i]=crs.getString("studentID").concat("  ").concat(crs.getString("studentLastName")).concat(", ").concat(crs.getString("studentFirstName"));
			} 
		}
			catch (SQLException e) {
			e.printStackTrace();
			}
		return s;
		}
public boolean isStudentBlocked(String studentId) {
	userInfo.deleteAll();// reset user info
	userInfo.addData(70);
	userInfo.addData(1);
	userInfo.addData(studentId);
	userInfo.addData(ParentIDId);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	try {
		crs.next();
		if(crs.getString("isBlocked").equals("1"))
			return true;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return false;
}
		
	}

